﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;

namespace Jib.Testbed
{
    public class CurrencyConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.GetType() == typeof(decimal?))
                if (value == null)
                    return string.Empty;
                else
                    return ((decimal?)value).Value.ToString("c");
            else if(value.GetType()==typeof(decimal))
                return ((decimal)value).ToString("c");
            return "Unknown";

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string price = value.ToString();
            double result;
            if (Double.TryParse(price, NumberStyles.Any, culture, out result))
                return result;
            return value;
        }
    }
}
